﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SimpleData.Infrastructure.Utils;

namespace System
{
	/// <summary>
	/// Validações dos dados de entrada
	/// </summary>
	public static class ObjectInputValidatorExtensions
	{
		public static IInputValidator<TValue> IfNull<TValue>( this IInputValidator<TValue> input )
		{
			if ( input.Value == null )
				input.Throws( new ArgumentNullException() );
			return input;
		}

		public static TNewType IfCastFails<TNewType>( this IInputValidator<Object> input )
			where TNewType : class
		{
			TNewType newType = input.Value as TNewType;

			if ( newType == null )
				throw new InvalidCastException();
			else
				return newType;
		}
	}
}
